package com.dylan.datacollection.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dylan.datacollection.R;
import com.dylan.datacollection.entity.JCEntity;
import com.dylan.datacollection.entity.MsgEntity;
import com.dylan.datacollection.net.HttpConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Vito's Pc on 2016/9/18 0018.
 */
public class RankListAdapter extends BaseAdapter {
    private List<JCEntity> mDatas = null;
    private Context mContext = null;
    private int mMsgType = 0;
    public RankListAdapter(int msgType, Context context, List<JCEntity> datas ){
        mContext = context;
        mMsgType = msgType;
        if ( null == mDatas ){
            mDatas = new ArrayList<>();
        }
        mDatas.addAll(datas);
    }

    public void setmDatas(List<JCEntity> mDatas, int msgType) {
        this.mDatas = mDatas;
        this.mMsgType = msgType;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public JCEntity getItem(int position) {
        return mDatas == null ? null : mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mDatas == null ? 0 : position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if ( null == convertView ){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.rank_item,null);
            holder = new Holder();
            holder.titleNameTextView = (TextView) convertView.findViewById(R.id.jc_title);
            holder.pjf = (TextView) convertView.findViewById(R.id.pjf_textView);
            holder.rankText = (TextView) convertView.findViewById(R.id.rank_textView);
//            holder.addressText = convertView.findViewById(R.id.address_textView);
//            holder.imgView = (ImageView) convertView.findViewById(R.id.item_msg_img_imageView);
            convertView.setTag(holder);
        }else {
            holder = (Holder) convertView.getTag();
        }
        JCEntity itemBean = getItem(position);
//        if (!TextUtils.isEmpty(itemBean.getCheck_img())){
//            holder.imgView.setVisibility(View.VISIBLE);
//            Glide.with(mContext).load(HttpConfig.HOST+itemBean.getCheck_img()).placeholder(R.mipmap.no_img).thumbnail(0.1f).error(R.mipmap.no_img).skipMemoryCache(false).into(holder.imgView);
//
//        }
        holder.titleNameTextView.setText(itemBean.getCheck_name());
        holder.pjf.setText(itemBean.getPjf());
//        holder.addressText.setText(itemBean.getAddress());
        int rank = position+1;
        holder.rankText.setText(String.valueOf(rank));
        return convertView;
    }

    class Holder{
        TextView titleNameTextView = null,pjf = null,addressText = null,rankText = null;
        ImageView imgView;
    }

}
